package com.panku.listener;

import java.net.MalformedURLException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.panku.util.XMLBean;
import com.panku.util.XmlUtil;

public class ActionListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("==============================系统退出.");
	}

	@Override
	public void contextInitialized(ServletContextEvent context) {
		try {
			ServletContext sc= context.getServletContext();
			String fileName =sc.getInitParameter("config_xml");
			String realPath = this.getClass().getClassLoader().getResource("/").getPath();
			String path=realPath+"../"+fileName;
			System.out.println("===========================配置文件路径:"+path);
			Map<String, XMLBean> results=XmlUtil.readXML(path);
			sc.setAttribute("actions", results);
			System.out.println("=================================系统初始化完毕!==================");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
